$(function () {
    // 加载formSelects
    layui.config({
        base: '/Public/layui-formSelects/dist/'
    }).extend({
        formSelects: 'formSelects-v4'
    });

   layui.use(['layer', 'form', 'formSelects'], function () {
      var form = layui.form(),
          layer = layui.layer,
          formSelects = layui.formSelects;

      // 执行渲染, 把原始select美化
      formSelects.render('modules');

      // 默认选中文件管理
      formSelects.value('modules', ['File'], true);

      form.on('submit(createTransfer)', function (data) {
          data.field.modules = formSelects.value('modules');
          var loading = layer.load(2, {
              shade: [0.5, '#fff'] //0.1透明度的白色背景
          });
          submitTransfer(data.field).then(function (response) {
              location.href = '/transfer/show?id=' + response.data.id;
          });
      });

      function submitTransfer(data)
      {
          return new Promise(function (resolve, reject) {
                $.post('/Transfer/store', data, function (response) {
                    if (response.errno) {
                        layer.alert(response.message);
                    } else {
                        resolve(response);
                    }
                });
          });
      }

      insDatetimePicker('.is-datetime', {
          language: 'zh-CN',
          format: 'yyyy-mm-dd hh:ii',
          startDate: new Date(),
          autoclose: true,
          todayBtn: true,
      })
   });
});